﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
using BLL;
//using BLL.RF.PowerTest;
using BLL.RF.ATETest;
using BLL.RF.TestRecord;
using Model;
//using Model.RF.PowerTest;
using Model.RF.ATETest;
using Model.RF.TestRecord;
using PrototypeTest.PIMandPowerAdd;
//using PrototypeTest.PowerMeas;

namespace PrototypeTest
{
    class Program
    {
        static void Main(string[] args)
        {
            #region
            //BLL.RF.Package.PackintoBox t = new BLL.RF.Package.PackintoBox();

            //tb_result_DFL t = new tb_result_DFL();
            //tb_result_DFL_Info tdi = new tb_result_DFL_Info()
            //{
            //    resultid = 0,
            //    partcode = "AJ3JSS100221A50H171435",
            //    testtime = DateTime.Now,
            //    testperiod = 130,
            //    testequipid = "MY8888",
            //    projname = "TLRRU_DFL",
            //    projver = "V0.1",
            //    tfpid = "V1.9",
            //    userid = "8888",
            //    totalresult = "0",
            //    itemresult = "0",
            //    itemselinfo = "1",
            //    itemselcnt = 1,
            //    itemcnt = 1,
            //    remark = "",
            //    IsPIM = false
            //};

            //List<tb_Param_DFL_Info> list = new List<tb_Param_DFL_Info>();
            //tb_Param_DFL_Info pdi = new tb_Param_DFL_Info()
            //{
            //    resultid = 0,
            //    partcode = "AJ3JSS100221A50H171435",
            //    Testequipid = "MY8888",
            //    ProcessNum = 1,
            //    UnitName = "TX1大功率测试",
            //    testtime = DateTime.Now,
            //    ParamName = "TX1大功率测试800mHz",
            //    Res = 0,
            //    ResValue = "8.88",
            //    ResDesc = "[6.66,+INF)",
            //};
            //list.Add(pdi);

            //bool i = t.tb_ATETestAndItem_Insert(tdi, "STR2400030", list);
            //Console.WriteLine(i.ToString());






            //OperatingSystem os = System.Environment.OSVersion;
            //Console.WriteLine("Platform: {0}", os.Platform);
            //Console.WriteLine("Service Pack: {0}", os.ServicePack);
            //Console.WriteLine("Version: {0}", os.Version);
            //Console.WriteLine("VersionString: {0}", os.VersionString);
            //Console.WriteLine("CLR Version: {0}", System.Environment.Version);

            //创建一个Bird基类数组，添加基类Bird对象，Magpie对象，Eagle对象，Penguin对象
            //Bird[] birds = { 
            //           new Bird(),
            //           new Magpie(),
            //           new Eagle(),
            //           new Penguin()
            //            };
            ////遍历一下birds数组
            //foreach (Bird bird in birds)
            //{
            //    bird.Eat();
            //}

            //分别使用传统的委托调用、使用匿名方法和Lamdba表达式方法完成同一功能
            //Console.WriteLine("传统的委托代码示例：");
            //LambdaDemo.FindListDelegate();
            //Console.Write("\n");
            //Console.WriteLine("使用匿名方法的示例：");
            //LambdaDemo.FindListAnonymousMethod();
            //Console.Write("\n");
            //Console.WriteLine("使用Lambda的示例：");
            //LambdaDemo.FindListLambdaExpression();

            //迭代器按需加载数据
            //foreach (var i in GetIterator())
            //{
            //    if (i == 2)
            //    {
            //        break;
            //    }
            //    Console.WriteLine(i);
            //}
            //Console.ReadKey();

            //自动属性、初始化器
            //MyObj m = new MyObj() { Title = "allen" };
            //Console.WriteLine(m.id);
            //Console.WriteLine(m.Title);
            //Console.ReadKey();

            //TestLinqToXml.XmlTransform();
            //TestLinqToXml.LinqGroupString();

            //Console.WriteLine(TestParm.addTwoEach());
            //Console.WriteLine(TestParm.addTwoEach(1));
            //Console.ReadKey();

            //Memonyout m = new Memonyout();
            //m.TestMemonyout();

            //Test t = new Test();

            //Customer c = new Customer();
            //IList<CustomerInfo> list = c.LoadEntities();
            //foreach (CustomerInfo ci in list)
            //{
            //    Console.WriteLine(ci.CustomerID + "  " + ci.CustomerName);
            //}

            //ProductType pt = new ProductType();
            //IList<ProductTypeInfo> list2 = pt.LoadEntities();
            //foreach (ProductTypeInfo pi in list2)
            //{
            //    Console.WriteLine(pi.ProductTypeID + "  " + pi.ProductTypeName + "  "
            //        + pi.CustomerID + "  " + pi.SN3BK + "  " + pi.MatchingSN + "  " + pi.IsPassive);
            //}

            //ZTEDataUpload z = new ZTEDataUpload();
            //z.Upload_ZTEData();
            //Console.ReadKey();

            //PowerTestUpload pu = new PowerTestUpload();
            //pu.UploadPowerTestData();
            #endregion

            #region
            //Test_Record tr=new Test_Record();
            //TestItem_Record tir=new TestItem_Record();
            //Test_RecordInfo tri = new Test_RecordInfo()
            //{
            //    ID = 1,
            //    ProductSN = "SFL0200062",
            //    RecordTime = DateTime.Now,
            //    TestPeriod = int.Parse("100"),
            //    ProductTypeID = "testS001",
            //    UserID = "123456",
            //    TestEquipID = "10.53.28.174",
            //    TestProjID = "1.0",
            //    Result = false,
            //    TestType = "OIP3测试"
            //};
            //TestItem_RecordInfo tiri = new TestItem_RecordInfo()
            //{
            //    ID = 1,
            //    ProductSN = "SFL0200062",
            //    RecordTime = DateTime.Now,
            //    TestItemName = "RX1" + "通道 OIP3 Test",
            //    TestItemDesc = "RX1" + "," + 1950 + "," + 1951,
            //    Spec = "30.5",
            //    ResValue = "-30",
            //    Result = false
            //};
            //tr.Test_Record_Insert_OIP3(tri);
            #endregion

            pti p=new pti();
            bool? IsOK = p.IsAutoBuild;
            if (!IsOK.HasValue)
            {
                Console.WriteLine("输出。。。");
            }

            Console.ReadKey();
        }

        public class pti
        {
            public bool IsAutoBuild { get; set; }
        }

        /*
        public class PowerTestUpload
        {
            public void UploadPowerTestData()
            {
                PowerTestInfo pi = new PowerTestInfo()
                {
                    ID = 272023,
                    ProductSN = "XA3JSS100786A10G481244",
                    RecordTime = DateTime.Now,
                    ProductTypeID = "STR4400032",
                    CouplerValue = "0",
                    UserID = "10307",
                    PCIP = "10.53.20.20",
                    TestStep = "一次",
                    SignalSource = "MY47420919",
                    IsPass = false
                };
                PowerTestItemInfo[] list = new PowerTestItemInfo[4]
                {
                   new PowerTestItemInfo(){    
                     ID=272023,
                    InputPower =Convert.ToDecimal("62.55"),
                    StartTime = DateTime.Now,
                    Duration = 60,
                    FrePoint =Convert.ToDecimal("869.25"),
                    LowLimit =Convert.ToDecimal("43.68"),
                    TestPort = "1", 
                    Measurement = Convert.ToDecimal("44.46"), 
                    IsPass = true
                   },
                   new PowerTestItemInfo(){  
                        ID=272023,
                        TestPort = "2",  
                        StartTime = DateTime.Now,
                        Duration = 60,
                        FrePoint =Convert.ToDecimal("880"), 
                        InputPower =Convert.ToDecimal("62.55"), 
                        LowLimit =Convert.ToDecimal("43.68"),
                        Measurement = Convert.ToDecimal("44.48"), 
                        IsPass = true
                   }
                   ,
                   new PowerTestItemInfo(){
                        ID=272023,
                         InputPower =Convert.ToDecimal("62.55"),
                    StartTime = DateTime.Now,
                    Duration = 60,
                    FrePoint =Convert.ToDecimal("869.25"),
                    LowLimit =Convert.ToDecimal("43.68"),
                    TestPort = "3", 
                    Measurement = Convert.ToDecimal("44.46"), 
                    IsPass = true
                   },
                   new PowerTestItemInfo(){
                    ID=272023,
                    InputPower =Convert.ToDecimal("62.55"),
                    StartTime = DateTime.Now,
                    Duration = 60,
                    FrePoint =Convert.ToDecimal("869.25"),
                    LowLimit =Convert.ToDecimal("43.68"),
                    TestPort = "4", 
                    Measurement = Convert.ToDecimal("44.46"), 
                    IsPass = true
                   }
                };
                try
                {
                    //MyWebService pt = new MyWebService();
                    PIMandPowerTest_AddbyManualServiceSoapClient pt = new PIMandPowerTest_AddbyManualServiceSoapClient("PIMandPowerTest_AddbyManualServiceSoap"
                        , "http://" + "10.53.20.170" + "/pa/WebService/ServiceForClient/PIMandPowerTest_AddbyManualService.asmx"
                        );
                    string str = pt.HelloWorld();
                    Console.WriteLine(str);
                }
                catch
                {
                    Console.WriteLine("上传失败");
                }
            }
        }

        
        public class MyWebService : PIMandPowerAdd.PIMandPowerTest_AddbyManualServiceSoapClient 
        {
            public MyWebService()
                : base()
            {
                this.Endpoint.Name = "PIMandPowerTest_AddbyManualServiceSoap";
                this.Endpoint.ListenUri = new Uri("http://10.53.20.170/pa/WebService/ServiceForClient/PIMandPowerTest_AddbyManualService.asmx");
            }
        }

        public class ZTEDataUpload
        {
            public void Upload_ZTEData()
            {
                tb_result_DFL_Info ti = new tb_result_DFL_Info()
                {
                    partcode = "A831900000000000000",
                    testtime = DateTime.Now,
                    testperiod = 259,
                    testequipid = "MY49305852",
                    tfpid = "MET_TLRRU_NFLD_TDD+V1.3+V4.0",
                    userid = "010307",
                    totalresult = "1",
                    itemresult = "00000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
                    itemselinfo = "11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111",
                    itemselcnt = 173,
                    itemcnt = 173,
                    remark = ""
                };
                List<tb_Param_DFL_Info> items = new List<tb_Param_DFL_Info>();
                tb_Param_DFL_Info item;
                item = new tb_Param_DFL_Info()
                {
                    Testequipid = "MET_TLRRU_NFLD_TDD+V1.3+V4.0",
                    ProcessNum = 1,
                    UnitName = "通道3性能测试",
                    testtime = DateTime.Now,
                    ParamName = "RX3 带外抑制1880-1915.2MHz",
                    Res = 0,
                    ResValue = "-43.4",
                    ResDesc = "(-INF,-36]"
                };
                items.Add(item);
                item = new tb_Param_DFL_Info()
                {
                    Testequipid = "MET_TLRRU_NFLD_TDD+V1.3+V4.0",
                    ProcessNum = 1,
                    UnitName = "通道3性能测试",
                    testtime = DateTime.Now,
                    ParamName = "RX3 带外抑制1-1640.3MHz",
                    Res = 0,
                    ResValue = "-98.16",
                    ResDesc = "(-INF,-51]"
                };
                items.Add(item);
                tb_result_DFL tb = new tb_result_DFL();
                if (tb.tb_ATETestAndItem_Insert(ti, "STR2400008", items))
                {
                    Console.WriteLine("上传成功");
                }
                else
                {
                    Console.WriteLine("上传失败");
                }
            }
        }

        public class Test
        {
            public static Foo Test1 = new Foo();
            public static string Test2 = "Test2";
            public string Test3 = "Test3";
            public Test() { }
        }

        public class Foo
        {
            public Foo()
            {
                throw new Exception();
            }
        }

        public class Memonyout
        {
            public void TestMemonyout()
            {
                var smallBlockSize = 90000;
                var largeBlockSize = 1 << 24;
                var count = 0;
                var bigBlock = new byte[0];
                try
                {
                    var smallBlocks = new List<byte[]>();
                    while (true)
                    {
                        GC.Collect();
                        bigBlock = new byte[largeBlockSize];
                        largeBlockSize++;
                        smallBlocks.Add(new byte[smallBlockSize]);
                        count++;
                    }
                }
                catch (OutOfMemoryException)
                {
                    bigBlock = null;
                    GC.Collect();
                    Console.WriteLine("{0} Mb allocated",
                        (count * smallBlockSize) / (1024 * 1024));
                }

                Console.ReadLine();
            }
        }

        public class TestParm              //两个方法，注释先后各注释一个，可以看到params关键字的作用
        {
            //public static int addTwoEach(int[] args)
            //{
            //    int sum = 0;

            //    foreach (var item in args)
            //    {
            //        sum += item + 2;
            //    }

            //    return sum;
            //}

            public static int addTwoEach(params int[] args)
            {
                int sum = 0;

                foreach (var item in args)
                {
                    sum += item + 2;
                }

                return sum;
            }
        }

        public class TestLinqToXml
        {
            public static void XmlTransform()
            {
                List<Student> students = new List<Student>()
                {
                    new Student {First="Svetlana", Last="Omelchenko", ID=111, Scores = new List<int>{97, 92, 81, 60}},
                    new Student {First="Claire", Last="O’Donnell", ID=112, Scores = new List<int>{75, 84, 91, 39}},
                    new Student {First="Sven", Last="Mortensen", ID=113, Scores = new List<int>{88, 94, 65, 91}},
                };

                // Create the query. 
                var studentsToXML = new XElement("Root",
                    from student in students
                    let x = String.Format("{0},{1},{2},{3}", student.Scores[0],
                            student.Scores[1], student.Scores[2], student.Scores[3])
                    select new XElement("student",
                               new XElement("First", student.First),
                               new XElement("Last", student.Last),
                               new XElement("Scores", x)
                            ) // end "student"
                        ); // end "Root" 

                // Execute the query.
                Console.WriteLine(studentsToXML);

                // Keep the console open in debug mode.
                Console.WriteLine("Press any key to exit.");
                Console.ReadKey();
            }

            public static void LinqGroupString()
            {
                string[] stringArray = { "zhangsan", "wangwu", "caoqi", "wangliu", "zhaoliu", "zhaoba", "lisi", "angirl", "lijiu", "zhangsi" };
                var query = from str in stringArray
                            group str by str[0] into stringGroup
                            orderby stringGroup.Key
                            select stringGroup;
                foreach (var item in query)
                {
                    Console.WriteLine(item.ToArray<string>()[0].ToString());
                    Console.WriteLine(item.Key);
                }
                Console.ReadKey();
            }
        }

        class Student
        {
            public string First { get; set; }
            public string Last { get; set; }
            public int ID { get; set; }
            public string Street { get; set; }
            public string City { get; set; }
            public List<int> Scores;
        }

        class Teacher
        {
            public string First { get; set; }
            public string Last { get; set; }
            public int ID { get; set; }
            public string City { get; set; }
        }

        public class MyObj
        {
            public Guid id { get; set; }
            public string Title { get; set; }
        }

        static IEnumerable<int> GetIterator()
        {
            Console.WriteLine("迭代器返回了1");
            yield return 1;
            Console.WriteLine("迭代器返回了2");
            yield return 2;
            Console.WriteLine("迭代器返回了3");
            yield return 3;
        }

        class LambdaDemo
        {
            //传统的调用委托的示例  
            public static void FindListDelegate()
            {
                //先创建一个泛型的List类  
                List<string> list = new List<string>();
                list.AddRange(new string[] { "ASP.NET课程", "J2EE课程", "PHP课程", "数据结构课程" });
                Predicate<string> findPredicate = new Predicate<string>(IsBookCategory);
                List<string> bookCategory = list.FindAll(findPredicate);
                foreach (string str in bookCategory)
                {
                    Console.WriteLine("{0}\t", str);
                }
            }
            //谓词方法，这个方法将被传递给FindAll方法进行书书籍分类的判断  
            static bool IsBookCategory(string str)
            {
                return str.EndsWith("课程") ? true : false;
            }

            //使用匿名方法来进行搜索过程  
            public static void FindListAnonymousMethod()
            {
                //先创建一个泛型的List类  
                List<string> list = new List<string>();
                list.AddRange(new string[] { "ASP.NET课程", "J2EE课程", "PHP课程", "数据结构课程" });
                //在这里，使用匿名方法直接为委托创建一个代码块，而不用去创建单独的方法  
                List<string> bookCategory = list.FindAll
                    (delegate(string str)
                    {
                        return str.EndsWith("课程") ? true : false;
                    }
                    );
                foreach (string str in bookCategory)
                {
                    Console.WriteLine("{0}\t", str);
                }
            }

            //使用Lambda来实现搜索过程  
            public static void FindListLambdaExpression()
            {
                //先创建一个泛型的List类  
                List<string> list = new List<string>();
                list.AddRange(new string[] { "ASP.NET课程", "J2EE课程", "PHP课程", "数据结构课程" });
                //在这里，使用了Lambda来创建一个委托方法  
                List<string> bookCategory = list.FindAll((string str) => str.EndsWith("课程"));
                foreach (string str in bookCategory)
                {
                    Console.WriteLine("{0}\t", str);
                }
            }
        }

        /// <summary>
        /// 鸟类：父类
        /// </summary>
        public class Bird
        {
            /// <summary>
            /// 吃：虚方法
            /// </summary>
            public virtual void Eat()
            {
                Console.WriteLine("我是一只小小鸟，我喜欢吃虫子~");
            }
        }

        /// <summary>
        /// 喜鹊：子类
        /// </summary>
        public class Magpie : Bird
        {
            /// <summary>
            /// 重写父类中Eat方法
            /// </summary>
            public override void Eat()
            {
                Console.WriteLine("我是一只喜鹊，我喜欢吃虫子~");
            }
        }

        /// <summary>
        /// 老鹰：子类
        /// </summary>
        public class Eagle : Bird
        {
            /// <summary>
            /// 重写父类中Eat方法
            /// </summary>
            public override void Eat()
            {
                Console.WriteLine("我是一只老鹰，我喜欢吃肉~");
            }
        }

        /// <summary>
        /// 企鹅：子类
        /// </summary>
        public class Penguin : Bird
        {
            /// <summary>
            /// 重写父类中Eat方法
            /// </summary>
            public override void Eat()
            {
                Console.WriteLine("我是一只小企鹅，我喜欢吃鱼~");
            }
        }
         */
    }
}
